package cn.hzu580.util;

import java.util.Comparator;
import java.util.Date;

import cn.hzu580.entity.Mission;

/**
 * 根据RANK分降序排序：排位越低越靠前显示，任务排位 = [（当前时间 - 任务创建时间）] * [（5 / 星级评分 + 2.5）] * [ 800 / ( 经验值 + 800 )]
 * @author 沫熊工作室 <a href="http://www.darhao.cc">www.darhao.cc</a>
 */
public class MissionComparartor implements Comparator<Mission> {
	
	private Date now = DateUtil.now();
	
	@Override
	public int compare(Mission o1, Mission o2) {
		if(o1.isIs_top() && !o2.isIs_top()){
			return -1;
		}else if(!o1.isIs_top() && o2.isIs_top()){
			return 1;
		}else{
			return getRANK(o1) - getRANK(o2) > 0 ? 1 : -1;
		}
	}

	private double getRANK(Mission m) {
		long time = now.getTime() - m.getCreate_time().getTime();
		double evaluate = 5.0 / (m.getOwner().getEvaluate() + 2.5);
		double experience = 800.0 / (m.getOwner().getExperience() + 800);
		double RANK = time * evaluate * experience;
		return RANK;
	}
}
